package ch.usi.inf.pf2.editor;

import java.awt.Color;

import ch.usi.inf.pf2.Sheet;
import ch.usi.inf.pf2.cell.Cell;

/**
 * Used to change the cell color
 * 
 * @author Lorenzo Baracchi
 *
 */
public class ChangeCellColor extends CellManagement
{
    private Color oldColor;
    private Color newColor;
    
    
    /**
     * Create an object able to change the color of the cell.
     * @param sheet The sheet where the cell is.
     * @param rowIndex The numeric index of the cell.
     * @param columnIndex The literal index of the cell.
     * @param newColor The new color wanted for the cell.
     */
    public ChangeCellColor (Sheet sheet, int rowIndex, int columnIndex, Color newColor)
    {
	   super(sheet, rowIndex, columnIndex);
	   this.newColor=newColor;
    }

    
    /**
     * Change the color of the cell and store the old one
     * into oldColor for possible undo actions.
     */
    @Override
    public void evaluate ()
    {
	   Cell c = sheet.getCell(getColumnIndex(), getRowIndex());
	   oldColor=c.getColor();
	   c.setColor(newColor);
    }

    
    /**
     * Allow to set in the field oldColor
     * a wanted old color for the cell.
     * @param oldColor The old color of the cell.
     */
    public void setOldColor (Color oldColor)
    {
	   this.oldColor = oldColor;
    }

    
    /**
     * @return The old color of the cell.
     */
    public Color getOldColor ()
    {
	   return oldColor;
    }

    
    /**
     * Allow to set in the field newColor
     * the new color of the cell.
     * @param newColor The new color of the cell.
     */
    public void setNewColor (Color newColor)
    {
	   this.newColor = newColor;
    }

    
    /**
     * @return The new color of the cell.
     */
    public Color getNewColor ()
    {
	   return newColor;
    }

    
    /**
     * Undo the previous change of color.
     */
    @Override
    public void restore ()
    {
	   Cell c = sheet.getCell(getColumnIndex(), getRowIndex());
	   c.setColor(getOldColor());
    }



}
